Introduction


PlaySound

Microsoft Windows provide the PlaySound API to play a sound from a file or a resource. To be able use this API you must un-comment #define WIN_DAC_ADC_SUPPORT from the stdafx.h file in your project as shown below.
Microsoft Windows proporciona la API PlaySound para reproducir un sonido desde un archivo o desde un recurso. Para poder usar esta API usted debe remover los comentarios de #define WIN_DAC_ADC_SUPPORT del archivo stdafx.h de su proyecto como se muestra debajo.

stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
//_________________________________________ GDI+
#define WIN_GDI_PLUS_ON
//_________________________________________ MIDI, Audio Card DAC's and ADC's (or GDI Game for timers)
#define WIN_DAC_ADC_SUPPORT
...


Problem 1
Create a dialog application called Music using Wintempla to play a sound from a WAVE file (*.wav). You will find a file called song.wav for this project.
Cree una aplicación de diálogo llamada Music para reproducir un sonido desde un archivo WAVE (*.wav). Usted necesitará un archivo llamado song.wav para este proyecto.

Step A
Copy the song.wav file to your project folder.
Copie el archivo song.wav a la carpeta folder.

song

Step B
Open the resource view, and right click over the Music.rc file to open the context menu: < Add Resource < Import . Select the wav file.
Abra la vista de recursos, y haga clic con el botón derecho del mouse en Music.rc para abrir el menú de contexto: < Add Resource < Import . Seleccione el archivo wav.

AddResource

WaveResource

Step C
Edit the Music.cpp file and run your program.
Edite el archivo Music.cpp y ejecute su programa.

Music.cpp
#include "stdafx.h" //________________________________________ Music.cpp
#include "Music.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR cmdLine, int cmdShow){
     Music app;
     return app.BeginDialog(IDI_MUSIC, hInstance);
}

void Music::Window_Open(Win::Event& e)
{
     //________________________________________ Play a file
     //::PlaySound(L"song.wav", NULL, SND_FILENAME | SND_ASYNC);
     //
     //________________________________________ Play a resource
     ::PlaySound(MAKEINTRESOURCE(IDR_WAVE1), this->hInstance,
               SND_RESOURCE | SND_ASYNC);

     //SND_SYNC play synchronously (default)
     //SND_ASYNC play asynchronously
     //SND_NODEFAULT silence (!default) if sound not found
     //SND_MEMORY pszSound points to a memory file
     //SND_LOOP loop the sound until next PlaySound

}


Tip
If you forget to select the audio option when creating the project, you may edit the stdafx.h file by removing the comments from the respective line.
Si usted olvida seleccionar la opción de audio al crear su proyecto, usted puede editar el archivo stdafx.h removiendo los comentarios de la línea respectiva.

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home